import QtQuick 2.7
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.0

Rectangle {
    width: parent.width
    height: 41
    radius: 5
    property string w_status: warn_status
    property color ws_color:   warn_status=="未读" ?"red": "green";
    RowLayout {
        id: rowLayout
        anchors.fill: parent
        Text {
            text: "" + libname + warn_type
            font.pixelSize: 20

        }
        Column {
            Layout.alignment: Qt.AlignRight
            Text {
                text: w_status
                color: ws_color
                font.pixelSize: 12
                anchors.right: parent.right
            }
            Text {
                text: ""+warn_time
                font.pixelSize: 12
                Layout.alignment: Qt.AlignRight
                elide: Qt.ElideRight
            }
        }


    }
    MouseArea {
        id: mouseArea
        anchors.fill: parent
        onClicked: {
            if(w_status == "未读") {
                Services.update_warn_status(id);
                w_status = "已读"
                ws_color = "green"
            }
            warn_popup.open()

        }


    }
    Popup {
        id: warn_popup
        height: 240
        width: 400
        padding: 0
        anchors.centerIn: Overlay.overlay
        Rectangle {
            id: warn_header
            width: parent.width
            height: 64
            color: "green"
            Text {
                text: qsTr("警报信息")
                font.pixelSize: 20
                anchors {
                    verticalCenter: parent.verticalCenter
                    leftMargin: 20
                    left: parent.left
                }
            }
            Button {
                anchors {
                    verticalCenter: parent.verticalCenter
                    rightMargin: 10
                    right: parent.right
                }
                background: Item {

                }
                icon {
                    source: "qrc:/images/close_face.png"
                }
                onClicked: {
                    warn_popup.close()
                }
            }


        }
        ColumnLayout {
            anchors.top: warn_header.bottom
            width: parent.width
            anchors.bottom: parent.bottom
            Text {
                Layout.leftMargin: 20
                Layout.topMargin: 20
                text: libname
            }
            Text {
                text: qsTr("库室名称：") + libname
                Layout.leftMargin: 20
            }
            Text {
                text: qsTr("警报级别：") + warn_level
                Layout.leftMargin: 20

            }
            Text {
                text: qsTr("警报类别：") + warn_type
                Layout.leftMargin: 20

            }
            Text {
                text: qsTr("警报时间：") + Qt.formatDateTime(warn_time, "yyyy-MM-dd hh:mm");
                Layout.leftMargin: 20
                Layout.bottomMargin: 20
            }

        }

    }

}
